package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-09-22
 * Time: 10:32
 */
public class ThreadDemon25 {
    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();
        Thread t1 = new Thread(()->{
            synchronized(A){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized(B){
                    System.out.println("尝试获取B锁");
                }

            }
        });

        Thread t2 = new Thread(()->{
            synchronized(B){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized(A){
                    System.out.println("尝试获取A锁");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
